package package1;
import package2.Protect1;//被protected修饰在不同包里子类访问导入公有父类所在的包才能访问(不同包的子类继承父类后才可以访问且不允许在主方法直接访问)
//只允许在子类用子类对象访问
public class Main extends Protect1{
   public void way() {
       Main try2 = new Main();
       System.out.println(try2.n);
   }
       public static void func(Animal727 w){
        System.out.println(w);

   }
   public static Animal727 fun4(){
       Dog dog4=new Dog("麦麦",4,"彩色");
       return dog4;
   }
    public static void main(String[] args){
        Cat cat1=new Cat("花花",10,"男");
        System.out.println(cat1.toString());
        Dog dog=new Dog("哈哈",10,"棕色");
         System.out.println(dog.toString());//子类与父类方法发生重写，调用时会调用子类的
        cat1.mimi();
        cat1.fun3();
        dog.wawa();
        dog.fun2();
        Dog2 dog2=new Dog2("憨憨",3,"白色","拣飞盘");
        System.out.println(dog2.toString());
        dog2.Do();
        Main cd=new Main();
        cd.way();
    //向上转型方法
        Animal727 am=new Dog("嘟嘟",7,"灰色");//第一种方法
        am.fun1();
        System.out.println(am);
       System.out.println( am.toString());
        /*am.fun2();虽然已经指向子类对象，但其类型依然属于父类，不可调用子类特有的方法*/
        Animal727 sd=new Dog("团团",2,"白色");
        func(sd);//第二种方法
        Animal727 am5=fun4();//第三种方法
        System.out.println(am5);
        }
}
